package futrueTask;

import java.util.Random;
import java.util.concurrent.*;

public class Demo {


    /**
     * Callalbe和Runnable的区别
     * <p>
     * Runnable run方法是被线程调用的，在run方法是异步执行的
     * <p>
     * Callable的call方法，不是异步执行的，是由Future的run方法调用的
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        long l = System.currentTimeMillis();

        ExecutorService executor = Executors.newCachedThreadPool();


        System.out.println(  "开始");


        for (int i = 0; i < 10; i++) {
            executor.execute( ()->{

                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if( new Random().nextBoolean()){
                    throw  new RuntimeException();
                }

                System.out.println("当前线程: .  " + Thread.currentThread());
            });
        }





    }

}